/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.bayu.services.dao;


import com.bayu.services.entity.Listrik;
import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author Bayu
 */
@Repository("listrikDao")
@Transactional
public class ListrikDao {
    private HibernateTemplate hibernateTemplate;

    @Autowired
    public void setSessionFactory(SessionFactory sessionFactory) {
	hibernateTemplate = new HibernateTemplate(sessionFactory);
    }

    	@Transactional(readOnly = false)
    public void save(Listrik listrik) {
       hibernateTemplate.saveOrUpdate(listrik);
    }
    @Transactional(readOnly = false)
    public void delete(Listrik listrik) {
        hibernateTemplate.delete(listrik);
    }
    @Transactional(readOnly = false)
    public void update(Listrik listrik) {
         hibernateTemplate.update(listrik);
    }

    public List<Listrik> getAll(String query) {
        return hibernateTemplate.find(query);
    }

    public List<Listrik> getAllByDate(String start, String end) {
        return hibernateTemplate.find("from Listrik where bulan between '"+start+"' and '"+end+"' order by bulan asc");
    }

    public List<Listrik> getById(Long id) {
        return hibernateTemplate.find("from Listrik where id="+id);
    }

    public List<Listrik> getAllByMonth(String month) {
       return hibernateTemplate.find("from Listrik where MONTH(bulan)='"+month+"' order by bulan asc");
    }

     public List custom(String query){
       return hibernateTemplate.find(query);

    }
}
